import json
import demjson


def check_res_data(data, expect_data):
    print('######################')
    res = json.loads(data).get('response', None)
    if res:
        res_json = json.dumps(res)
        res_str = res_json.replace('\\n', '').replace('\\t', '').replace('false', 'False').replace('true', 'True')
        res_j = json.loads(res_str)
        res_data = eval(res_j)
        res_code = res_data['code']
        if res_code == 'PRO000':
            res_data = res_data['data']
            try:
                res_data_dic = json.loads(json.dumps(res_data))
            except Exception as e:
                res_data_dic = demjson.decode(res_data)  # 转成标准的json格式
        else:
            res_data_json = json.dumps(res_data).encode('utf-8').decode('unicode_escape')  # 将\\uxxxx转为Unicode字符串

            raise Exception('接口返回报错，报错信息为：{}'.format(data.json()))
        print(res_data_dic)
        return res_data_dic
    else:
        raise Exception('接口返回报错，报错信息为：{}'.format(json.dumps(data.json())))
